package com.testhomepsg;

import java.util.Vector;

import app.kernel.api.PsgFacade;
import config.PSG_Configuration;

public class TestPsgApp{
	
	public static void main (String[] args)
	{
    	String defaultIP 		= PSG_Configuration.defaultIP;
    	int defaultPort 		= PSG_Configuration.defaultPort;
    	
    	String IPPort = defaultIP+":"+defaultPort;
    	
    	String ID_KEY 		= "http://"+defaultIP+ ":"+(defaultPort+(0))+"/xmlrpc";
    	
    	String[] attrLookup = {"name", "phonePickedUp", "tvOn", "foodOnTable", "personAtDoor", "personEating", "personDrinking",};
    	Vector<String> results = new Vector<String>();
    	
        try
        {
        	PsgFacade psgKernelFacade = new PsgFacade(ID_KEY, defaultIP, defaultPort);
        	psgKernelFacade.register(IPPort);
        	Thread.sleep(2000);
        	for (int i=0; i<attrLookup.length; i++){
        		System.err.println("[ Query "+(i+1)+" ]");
        		String res = psgKernelFacade.queryMCS("select "+attrLookup[i]+" from home",ID_KEY);
        		results.add(res);
        		System.out.println(res);
        		
        	}
        	System.err.println("Final");
        	for (int i=0; i<results.size(); i++){
        		System.out.println(attrLookup[i]+" = "+results.get(i));
        	}
        	Thread.sleep(1000);
//        	psgKernelFacade.leave();
        	Thread.sleep(1000);
        	System.err.println("After Leaving");

        	results = new Vector<String>();
        	for (int i=0; i<attrLookup.length; i++){
        		System.err.println("[ Query "+(i+1)+" ]");
        		String res = psgKernelFacade.queryMCS("select "+attrLookup[i]+" from home",ID_KEY);
        		results.add(res);
        		System.out.println(res);
        	}
        	System.err.println("Final");
        	for (int i=0; i<results.size(); i++){
        		System.out.println(results.get(i));
        	}
        	
        	
        }
        catch (Exception e)
        {
        }
    }
}